package com.example.feifei.newproject;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.feifei.utils.DividerItemDecoration;
import com.example.feifei.adapter.RecyclerViewAdapter;
import com.example.feifei.utils.GrideItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * RecycleView简单使用
 * Created by feifei on 2017/7/3.
 */

public class RecycleViewActivity extends Activity {

    private RecyclerView recyclerView;
    //展示数据
    List<String> listDatas;

    private RecyclerViewAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycleview);
        recyclerView = (RecyclerView) this.findViewById(R.id.recyclerView);
        initData();
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));
        //为RecyclerView设置适配器
        recyclerView.setAdapter(adapter = new RecyclerViewAdapter(RecycleViewActivity.this,listDatas));
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST));
//        recyclerView.addItemDecoration(new GrideItemDecoration(this));
    }
    //添加数据
    private void initData(){
        listDatas = new ArrayList<>();
        for(int i='A';i<'Z';i++){
            listDatas.add(""+(char)i);
        }
    }
}
